package com.wxb.hello.auth.handler;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Feng Yu
 * @version V1.0
 * @date 2017-12-27
 */
public class CustLogoutSuccessHandler implements LogoutSuccessHandler {

    private static final Logger logger = LoggerFactory.getLogger(CustLogoutSuccessHandler.class);

    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        JSONObject obj = new JSONObject(2);
        obj.put("rtnCode", "-7958");
        obj.put("rtnMsg", "登录SESSION失效");
        logger.info("logout handler: 构建成功登出报文成功,报文--》{}", obj.toJSONString());

        response.setHeader("Content-Type", "application/json;charset=utf-8");
        response.getWriter().print(obj.toJSONString());
        response.getWriter().flush();
    }
}
